local lsp_installer = require("nvim-lsp-installer")
local lspconfig = require("lspconfig")
lsp_installer.setup {}

-- 安装列表
-- { key: 语言 value: 配置文件 }
-- key 必须为下列网址列出的名称
-- https://github.com/williamboman/nvim-lsp-installer#available-lsps
local servers = {
    lua_ls = require("lsp.config.lua"), -- lua/lsp/config/lua.lua
    pyright = require("lsp.config.python"),
    clangd = require("lsp.config.clangd")
}
-- 自动安装 Language Servers
for name, _ in pairs(servers) do
    local server_is_found, server = lsp_installer.get_server(name)
    if server_is_found then
        if not server:is_installed() then
            print("Installing " .. name)
            server:install()
        end
        if server:is_installed() then
            lspconfig[name].setup(servers[name])
        end
    else
        print(name .. " server not found, install manually please...")
    end
end
-- lsp install not include lua_ls, install manually
lspconfig['lua_ls'].setup(servers['lua_ls'])

-- 新版本直接用lspconfig配置
--lsp_installer.on_server_ready(function(server)
    --local config = servers[server.name]
    --if config == nil then
        --return
    --end
    --if config.on_setup then
        --config.on_setup(server)
    --else
        --server:setup({})
    --end
--end)
